package com.reliable.service.enums;

import lombok.Getter;

/**
 * 邀请码状态枚举
 */
@Getter
public enum InviteStatusEnum {

    //未使用
    UNUSED(0, "未使用"),
    VALID(1, "有效"),
    EXPIRED(2, "过期"),
    // 禁用
    DISABLED(3, "禁用");

    private final int code;
    private final String desc;

    InviteStatusEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    /**
     * 根据code获取描述
     */
    public static String getDescByCode(int code) {
        for (InviteStatusEnum status : InviteStatusEnum.values()) {
            if (status.getCode() == code) {
                return status.getDesc();
            }
        }
        return null;
    }

    /**
     * 根据code获取枚举对象
     */
    public static InviteStatusEnum getByCode(int code) {
        for (InviteStatusEnum status : InviteStatusEnum.values()) {
            if (status.getCode() == code) {
                return status;
            }
        }
        throw new IllegalArgumentException("Invalid InviteStatus code: " + code);
    }
}
